<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTalkTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users_chat_list', function (Blueprint $table) {
            $table->unsignedInteger('id', true)->comment('聊天列表ID');
            $table->unsignedInteger('user_id')->comment('用户ID');
            $table->unsignedInteger('friend_id')->comment('接收方的用户ID');
            $table->unsignedInteger('status')->default(1)->default(1)->comment('状态[0:已删除;1:正常]');;
            $table->dateTime('created_at')->nullable(true)->comment('创建时间');
            $table->dateTime('updated_at')->nullable(true)->comment('更新时间');

            $table->index(['user_id', 'friend_id'], 'idx_user_id_friend_id');
        });

        DB::statement("ALTER TABLE `users_chat_list` comment '用户聊天列表'");

        Schema::create('users_chat_records', function (Blueprint $table) {
            $table->unsignedInteger('id', true)->comment('聊天记录ID');
            $table->unsignedInteger('user_id')->default(0)->comment('发送消息的用户ID[0:代表系统消息]');
            $table->unsignedInteger('receive_id')->default(0)->comment('接收消息的用户ID');
            $table->text('content')->nullable(true)->charset('utf8mb4')->comment('文本消息');
            $table->dateTime('created_at')->nullable(true)->comment('发送消息的时间');

            $table->index(['user_id', 'receive_id'], 'idx_userid_receiveid');
        });

        DB::statement("ALTER TABLE `users_chat_records` comment '用户聊天记录表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users_chat_list');
        Schema::dropIfExists('users_chat_records');
    }
}
